// Python C/api
#include <python2.7/Python.h>

static PyObject* addlist_add(PyObject* self, PyObject* args){
    PyObject * listobj;
    if (!PyArg_ParseTuple(args,"O", &listobj))
        return NULL;

    long length=PyList_Size(listobj);
    int i,sum=0;
    for(i=0;i<length;i++){
        PyObject* temp=PyList_GetItem(listobj,i);
        long elem=PyInt_AsLong(temp);
        sum+=elem;
    }
    return Py_BuildValue("i",sum);
}

static char addlist_docs[]="add():add all elements of the list\n";

static PyMethodDef addlist_funcs[] = {
    {"add", (PyCFunction)addlist_add, METH_VARARGS, addlist_docs},
    {NULL,NULL,0,NULL}
};


PyMODINIT_FUNC initaddlist(void){
    Py_InitModule4("addlist", addlist_funcs,"xsxs");
}